﻿/*
 * @RELATION <relation-name>
        where <relation-name> is a string. The string must be quoted if the name includes spaces.
 
 * @ATTRIBUTE <attribute-name> <datatype>
        where the <attribute-name> must start with an alphabetic character. If spaces are to be included in the name then the entire name must be quoted.
        The <datatype> can be any of the four types currently (version 3.2.1) supported by Weka:
            numeric
            <nominal-specification>
            string
            date [<date-format>]
 * @DATA
        Each instance is represented on a single line, with carriage returns denoting the end of the instance.
 

 
 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Toolbox
{
    class ARFFType
    {
        private string _relation = "";
        private Dictionary<string, string> _attribute = new Dictionary<string,string>();
        private List<string> _data = new List<string>();

        public string Relation
        {
            get { return _relation; }
            set
            {
                if (_relation.Contains(" "))
                    _relation = "\'" + value + "\'";
                else
                    _relation = value; 
            }
        }

        public void AddAttribute(string attributename, string datatype)
        {
            if (_attribute.ContainsKey(attributename) == false)
            {
                _attribute.Add(attributename, datatype);
            }
            else throw new Exception("Attribute da ton tai.");
        }
        public void DelAttribute(string attributename)
        {
            if (_attribute.ContainsKey(attributename) == false)
            {
                _attribute.Remove(attributename);
            }
            else throw new Exception("Attribute khong ton tai.");
        }
        public int CountAttribute { get { return _attribute.Count; } }
        public bool HasAttribute
        {
            get
            {
                if (_attribute.Count == 0) return false;
                else return true;
            }
        }

        public void AddData(string data)
        {
            _data.Add(data);
        }
        public int CountData { get { return _data.Count;  } }
        public bool HasData
        {
            get
            {
                if (_data.Count == 0) return false;
                else return true;
            }
        }

        public override string ToString()
        {
            return _relation;
        }

        public string ExportString()
        {
            string result = "";
            result += "@RELATION " + _relation + "\r\n";
            foreach (KeyValuePair<string,string> att in _attribute)
            {
                result += "@ATTRIBUTE " + att.Key + " " + att.Value + "\r\n";
            }
            result +=  "@DATA\r\n";
            foreach (string s in _data)
            {
                result += s + "\r\n";
            }
            return result;
        }
    }
}
